home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asm_subr.arc / XORBOX < prev    next >
Encoding:
Text File  |  1986-01-20  |  4.5 KB  |  172 lines

  1. ;-------------------------xorbox routine begins--------------------------+
  2. ; NAME  XORBOX
  3. ;
  4. ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
  5. ;         page :  137
  6. ;
  7. ; ROUTINE FOR XOR FILLING A RECTANGULAR BOX WITH COLOR
  8. ;
  9. ; FUNCTION: This routine fills a rectangular box in the color graphics
  10. ; screen with a given color using the exclusive-or function.  Each pixel
  11. ; in the rectangle is colored with a color obtained by XOR-ing its orig-
  12. ; inal color with a specified color.  The function is useful for making
  13. ; cursors.
  14. ;
  15. ; INPUT: Upon entry:
  16. ;
  17. ;    x-coordinate of upper left corner is in x1
  18. ;    y-coordinate of upper left corner is in y1
  19. ;    x-coordinate of lower right corner is in x2
  20. ;    y-coordinate of lower right corner is in y2
  21. ;    color of the rectangle is in bits 0 and 1 of color
  22. ;
  23. ; OUTPUT: Just to the screen.
  24. ;
  25. ; REGISTERS USED:  No registers are modified.
  26. ;
  27. ; SEGMENTS REFERENCED:  Upon entry ES must point to the video RAM at
  28. ; 0B8000h and DS must point to the following lookup table for color
  29. ; masks:
  30. ;
  31. ; xtable    dw    0FFC0h, 0FFF0h, 0FFFCh, 0FFFFh
  32. ;        dw    03FC0h, 03FF0h, 03FFCh, 03FFFh
  33. ;        dw    00FC0h, 00FF0h, 00FFCh, 00FFFh
  34. ;        dw    003C0h, 003F0h, 003FCh, 003FFh
  35. ;
  36. ; ROUTINES CALLED:  None
  37. ;
  38. ; SPECIAL NOTES: No bounds checking is performed. The coordinates must
  39. ; be in range and in order.  That is, the following case must be true:
  40. ;
  41. ;    0 <= x1 <= x2 <= 319
  42. ;    0 <= xy <= y2 <= 119    
  43. ;
  44. ; ROUTINE TO FILL A RECTANGULAR BOX
  45. ;
  46. xorbox    proc    far
  47. ;
  48.     push    si        ; save registers
  49.     push    di
  50.     push    dx
  51.     push    bx
  52.     push    cx
  53.     push    ax
  54. ;
  55. ; determine byte position for start
  56. ;
  57. ; get y contribution
  58.     mov    ax,y1        ; get starting y-coordinate
  59.     mov    ah,al        ; replicate for odd-even bank
  60.     and    ax,1FEh        ; just one bit gets moved
  61.     sal    ax,1        ; times 4
  62.     sal    ax,1        ; times 8
  63.     sal    ax,1        ; times 16
  64.     mov    di,ax        ; address gets 16 * y-coord
  65.     and    di,7FFh        ; not the odd-even bit
  66.     sal    ax,1        ; times 32
  67.     sal    ax,1        ; times 64
  68.     add    di,ax        ; address gets 80 * y-coord
  69. ;
  70. ; add in x contribution
  71.     mov    ax,x1        ; get x coord
  72.     sar    ax,1        ; divide
  73.     sar    ax,1        ; by 4
  74.     add    di,ax        ; beginning offset
  75. ;
  76. ; count for outer loop
  77.     mov    cx,y2        ; ending y-coord
  78.     sub    cx,y1        ; minus starting y coord
  79.     inc    cx        ; plus 1
  80. ;
  81. ; count for inner loop
  82.     mov    si,x2        ; ending x-coord
  83.     sar    si,1        ; divide
  84.     sar    si,1        ; by 4
  85.     mov    ax,x1        ; starting x-coord
  86.     sar    ax,1        ; divide
  87.     sar    ax,1        ; by 4
  88.     sub    si,ax        ; take the difference
  89. ;
  90. ; get the color
  91.     mov    bx,color    ; get the color
  92.     and    bx,3        ; just between 0 and 3
  93.     mov    dl,cbytes[bx]    ; look up color pattern
  94. ;
  95. ; determine mask for starting and ending bytes
  96.     mov    bx,x1        ; starting byte
  97.     and    bx,3        ; just the pixel posn
  98.     sal    bx,1        ; times 2
  99.     sal    bx,1        ; times 4
  100.     mov    ax,x2        ; ending byte
  101.     and    ax,3        ; just the pixel posn
  102.     add    bx,ax        ; 4 * starting-ending
  103.     sal    bx,1        ; 8 * starting + 2 * ending
  104.     mov    bx,xtable[bx]    ; look up the masks
  105. ;
  106. ; set up masked color bytes
  107.     mov    dh,dl        ; color for the left bytes
  108.     mov    ah,dl        ; color for the middle bytes
  109.     and    dx,bx        ; mask left and right color bytes
  110. ;
  111.     cld            ; forward
  112. ;
  113. xboxloop:
  114.     push    cx        ; save count of outer loop
  115.     push    di        ; save initial byte posn
  116. ;
  117.     mov    cx,si        ; count for inner loop
  118. ;
  119. ; check for only one byte
  120.     mov    al,bh        ; get the mask
  121.     jcxz    xboxloop3    ; if ending byte coincides
  122. ;
  123. ; xor leftmost byte of the scan line
  124.     xor    es: [di],dh    ; xor color into memory
  125.     inc    di        ; next byte
  126.     dec    cx        ; count it
  127.     jcxz    xboxloop2    ; done ?
  128. ;
  129. ; xor middle byte of scan line
  130. xboxloop1:
  131.     xor    es: [di],ah    ; xor color byte into memory
  132.     inc    di        ; next byte
  133.     loop    xboxloop1    ; loop to get all the middle
  134. ;
  135. ; handle the rightmost byte
  136. ;
  137. ; come here if two or more bytes
  138. xboxloop2:
  139.     mov    al,0FFh        ; set the full mask
  140. ;
  141. ; in all cases come here to adjust the masks
  142. xboxloop3:
  143.     and    al,bl        ; bring in right part of the mask
  144.     and    dl,al        ; clear left part of color if needed
  145. ;
  146. ; xor the rightmost byte
  147.     xor    es: [di],dl    ; xor byte into memory
  148.     inc    di        ; next byte
  149. ;
  150. ; compute next scan line
  151.     pop    di        ; restore address of left side of box
  152.     test    di,2000h    ; odd or even line ?
  153.     jz    xboxloop4    ; skip if even
  154.     add    di,80        ; add 80 bytes per line if odd
  155. ;
  156. xboxloop4:
  157.     xor    di,2000h    ; changes banks in any case
  158.     pop    cx        ; restore count for outer loop
  159.     loop    xboxloop    ; next scan line
  160. ;
  161.     pop    ax        ; restore registers
  162.     pop    cx
  163.     pop    bx
  164.     pop    dx
  165.     pop    di
  166.     pop    si
  167. ;
  168.     ret            ; return
  169. ;
  170. xorbox    endp
  171. ;-------------------------xorbox routine ends---------------------------+
  172.